﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;

namespace FYPDemo
{
    public partial class WebForm5 : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            ListView1.ItemCommand += new EventHandler<ListViewCommandEventArgs>(ListView1_ItemCommand);
        }

        void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            int ID = Convert.ToInt32(e.CommandArgument);
            ProductManagement.DeleteProduct(ID);
            
            Response.Redirect("DisplayProductForVendor.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindDDLCategory();
                string vendor = Request.QueryString["vendor"];

                if (vendor != "")
                {
                    ViewState["vendor"] = vendor;
                    DataTable dt = ProductManagement.displayProduct("All", vendor);

                    ListView1.DataSource = dt;
                    ListView1.DataBind();
                }
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string category = ddlCategory.SelectedItem.ToString();
            string vendor = "";

            if(ViewState["vendor"] != null)
                vendor = ViewState["vendor"].ToString();            

            DataTable dt = ProductManagement.displayProduct(category, vendor);

            ListView1.DataSource = dt;
            ListView1.DataBind();
        }

        protected void bindDDLCategory()
        {
            DataTable dt = ProductManagement.bindProductCategory();

            ddlCategory.DataSource = dt;
            ddlCategory.DataTextField = "Value";
            ddlCategory.DataValueField = "CategoryID";
            ddlCategory.DataBind();
        }
    }
}